<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<link rel="stylesheet" href="../../css/style.css" type="text/css">

<script type="text/javascript" src="../js/httpRequest.js"></script>
<script type="text/javascript">
	//삭제
	function del(){
		var cate_no =${cvo.cate_no} ;
		
		if(confirm("삭제하시겠습니까?")==false) return;
		
		if(cate_no==9){
			f.action = "notice_delete.do";
			f.submit();
		}
		else if(cate_no!=9){
			f.action ="board_delete.do";
			f.submit();
		}
	}
	
	//수정
	function modify(){
		f.action="board_modifyForm.do?state=modify";
		f.submit();
	}
	
	//취소
		

	
	
	
///////////////////////////////////////////////////////댓글	
	//#1.댓글보기
	function replyView(b_no){
		var frame = document.getElementById("reply_frame");
		
		if(frame.style.display=="none"){
			frame.style.display="block";
			sendRequest("../ajax/get_reply.jsp","b_no="+b_no, resultReply,"POST");
		}
		else if(frame.style.display=="block"){
			frame.style.display="none";
		}
	}
	
	//댓글내용삭제
	function replyViewDel(){
		var dv_1 = document.getElementById("tb_view").childNodes[1];
		var cnt_1 = dv_1.childNodes.length;
		for(var i=0; i<cnt_1; i++){
			dv_1.removeChild(dv_1.childNodes[0]);
		}
	}
	
	//#2.댓글보기
	function resultReply(){
		//backgroundChange();
		
		if(xhr.readyState==4 && xhr.status==200){
			replyViewDel();
			
			var res=eval(xhr.responseText);
			var tb_1 = document.getElementById("tb_view").childNodes[1];
			if(res.length > 0){
				for(var i=0; i<res.length; i++){
					var tr_1 = document.createElement("tr");
					var tr_2 = document.createElement("tr");
					
					var td_1 = document.createElement("td");
					var td_2 = document.createElement("td");
					
					var alias=f.alias.value;
					
					td_1.setAttribute("id","td_1");
					td_1.setAttribute("width","100");
					/* <td style="font-size: large;"> */
					/* <td style="font-weight: bold;"> */
					/* style="color: blue;" */
					/* padding-left: 30px  style="padding: 10px"*/
					td_1.setAttribute("style","font-weight:bold;padding-left: 30px;color:white;");
					
					
					td_2.setAttribute("id","td_2");
					td_2.setAttribute("style","color:gray; font-size:small;");
					
					
					var td_3 = document.createElement("td");
					td_3.setAttribute("colspan","2");
					td_3.setAttribute("id","td_3"+i);
					td_3.setAttribute("class","tr_bottom");
					td_3.setAttribute("style","font-size:medium; padding-left: 40px");
					
					td_1.innerHTML=res[i].b_writer;
					td_2.innerHTML=res[i].b_writedate+"&nbsp;&nbsp;";
					
					if(alias==res[i].b_writer){
							var a_1 = document.createElement("input");
							a_1.setAttribute("type","button");
							a_1.setAttribute("class","pink_s_button");
							a_1.setAttribute("onclick", "replyModifyForm("+res[i].b_no+","+i+")");
							a_1.setAttribute("value","수정");
							
							var a_2 = document.createElement("input");
							a_2.setAttribute("type","button");
							a_2.setAttribute("class","pink_s_button");
							a_2.setAttribute("onclick", "replyDelete("+res[i].b_no+")");
							a_2.setAttribute("value","삭제");
							
							td_2.appendChild(a_1);
							td_2.appendChild(a_2);
					}
					
					
					td_3.innerHTML="→"+ "&nbsp;&nbsp;" + res[i].b_content;
					
					tr_1.appendChild(td_1);
					tr_1.appendChild(td_2);
					tr_2.appendChild(td_3);
					
					tb_1.appendChild(tr_1);
					tb_1.appendChild(tr_2);
					
				}
			}
		}
		document.getElementById("reply_content").value="";
	}
	
	
	//댓글쓰기
	function replyWrite(b_no){
		
		var	content=document.getElementById("reply_content").value;
		
		alert(content);
		content = content.replaceAll("\r","");
		content = content.replaceAll("\n","<br>");
		
		var menu_no=${cvo.menu_no};
		var cate_no=${cvo.cate_no};
		var title_no=${cvo.title_no};

		var state = "write";
		
		alert("와우2");
		
		
		var param="b_no="+b_no+"&b_content="+encodeURIComponent(content)+
				   "&menu_no="+menu_no+"&cate_no="+cate_no+"&title_no="+title_no+"&reply_state="+state;
		sendRequest("../ajax/get_reply.jsp", param, resultReply, "POST");
	}
	
	//문자열대체
	String.prototype.replaceAll = replaceAll;
	function replaceAll(value1, value2){
		var strTemp = this;
		while(1){
			if(strTemp.indexOf(value1)!=-1){
				strTemp = strTemp.replace(value1, value2);
			}else 
				break;
		}
		return strTemp;
	}
	
</script>


</HEAD>
<BODY>
	<form action="" name="f" method="post">
		<input type="hidden" name="id" value="${sessionScope.id }"> <input
			type="hidden" name="alias" value="${sessionScope.alias }"> <input
			type="hidden" name="b_no" value="${cvo.b_no }"> <input
			type="hidden" name="b_subject" value="${cvo.b_subject }"> <input
			type="hidden" name="b_writer" value="${cvo.b_writer }"> <input
			type="hidden" name="b_filename" value="${cvo.b_filename }"> <input
			type="hidden" name="b_content" value="${cvo.b_content }"> <input
			type="hidden" name="menu_no" value="${cvo.menu_no }"> <input
			type="hidden" name="cate_no" value="${cvo.cate_no }"> <input
			type="hidden" name="title_no" value="${cvo.title_no }">


		<table width="700" class="tb_outside1" style="padding: 10px;">
		
			<tr>
				<td class="td_padding" width="500"  style="font-size: large;"><strong>${cvo.b_subject}
				&nbsp;|&nbsp;</strong>
				<c:if test="${cvo.cate_no==6}">자유게시판</c:if>
				<c:if test="${cvo.cate_no==7}">지역게시판</c:if>
				<c:if test="${cvo.cate_no==8}">그룹게시판</c:if>
				<c:if test="${cvo.cate_no==0}">공지게시판</c:if>
				</td>
				<td class="td_padding" width="200" align="right" >${cvo.b_writedate}</td>
			</tr>
			
			<tr>
				<td colspan="2" class="tr_bottom"></td>
			</tr>

			
			<tr class="tr_bottom">
				<td class="td_padding"><strong>작성자:${cvo.b_writer}</strong></td>
		<!-- 파일이있으면 -->
			<c:if test="${cvo.b_filename!='no_file'}">
					<td class="td_padding"><a href="#" onclick="download('${cvo.b_filename}')">${cvo.b_filename}</a></td>
			</c:if>
			<c:if test="${cvo.b_filename=='no_file'}">
					<td class="td_padding" align="right" style="font-size: small;color:white;">nofile</td>
			</c:if>
			</tr>
			
			<tr>
				<td class="td_padding" colspan="2" height="300">${cvo.b_content }</td>
			</tr>
			
		
			<tr>
				<td colspan="2" align="right">
			<!-- 댓글보기 -->
				<input type="button"  class="pink_s_button"  value="댓글" onclick="replyView(${cvo.b_no})" />
			<!-- 목록보기 -->
				<!-- 공지사항아니면 -->
				<c:if test="${cate_no!=9 }">
				<a href="../main/community_main.do?menu_no=${menu_no }&cate_no=${cate_no}&title_no=${title_no }&state=list&page=${nowPage}" >
				<input type="button" value ="목록"  class="pink_s_button" >
				</a>				
				</c:if>
				<!-- 공지사항이면 -->
				<c:if test="${cate_no==9 }">
				<a href="../main/community_main.do?menu_no=${menu_no }&cate_no=${cate_no}&title_no=${title_no }&state=notice&page=${nowPage}" >
				<input type="button" value ="목록"  class="pink_s_button" >
				</a>				
				</c:if>
				
			<!-- 로그인정보와글쓴이일치하면 -->
			<c:if test="${cvo.b_writer==alias}">
			<!-- 수정 -->
				<input type="button" value ="수정"  class="pink_s_button"  onclick="modify()">
			<!-- 삭제 -->
	        	<input type="button" value ="삭제"  class="pink_s_button"  onclick="del()">
	        </c:if>
				</td>
			</tr>
</table>			
</form>				

<!-- /////////////////////////////////////////////////////////////////////////////// -->
			<div id="reply_frame" style="display: none;" class="tb_outside2">
				<!-- <table id="tb_view" width="600" border="1" cellpadding="0" cellspacing="0" > -->
				<table id="tb_view"  width="700">
					<thead></thead>
					<tbody></tbody>
				</table>
				
				<table id="tb_write" width="700" border="0" cellpadding="0" cellspacing="0"
				style="padding: 10px" >
					<thead></thead>
					<tbody>
						<tr>
							<td>
							<textarea rows='5' cols='80' id='reply_content' name="reply_content"></textarea>
							<a onclick="replyWrite(${cvo.b_no})" >
							<input type="button" value ="입력"  class="pink_m_button" >
							</a>
							</td>
						</tr>
							
					</tbody>
				</table>
			</div>

</BODY>
</HTML>
